package com.cg.design.depthdesign.builder.components;

/**
 * 产品特征 1：发动机
 *
 * @program: LeetCode->Engine
 * @author: cg
 * @create: 2022-05-08 16:16
 **/
public class Engine {

    /**
     * 体积
     */
    private final double volume;
    /**
     * 里程
     */
    private double mileage;
    /**
     * 是否启动
     */
    private boolean started;

    public Engine(double volume, double mileage) {
        this.volume = volume;
        this.mileage = mileage;
    }

    /**
     * 启动发动机
     */
    public void on() {
        started = true;
    }

    /**
     * 关闭发动机
     */
    public void off() {
        started = false;
    }

    public boolean isStarted() {
        return started;
    }

    /**
     * 前进
     * @param mileage 里程数
     */
    public void go(double mileage) {
        if (started) {
            this.mileage += mileage;
        } else {
            System.err.println("Cannot go(), you must start engine first!");
        }
    }

    public double getVolume() {
        return volume;
    }

    public double getMileage() {
        return mileage;
    }
}
